<?php 
/**
 * @file aa.php	Fixed!
 * @version 0.1
 * @desc 账户管理
 */
if(!defined('ACCOUNT_INIT'))
	exit('Access Denied!');

/* 定义全局变量 */
global $gLD;
$user_id = $gLD['user_id'];
$nick = $gLD['user_snick'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>账户管理</title>
<link rel="stylesheet" href="style.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
</head>
<body oncontextmenu="window.event.returnValue=false">

<table width="617" height="482" border="0" cellpadding="6" cellspacing="0">
<tr>
<td valign="top">
<?php  //显示头部文件
    showHeader($gLD['module']); ?>
<table width="605" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="379" height="436">

<table width="371" height="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#012849">
            <tr>
              <td height="434" valign="top" bgcolor="#4484c1"><table width="361" border="0" cellspacing="0" cellpadding="0">
                <tr>
                  <td width="361" height="261" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="25" align="center" bgcolor="#014075"><span class="blue1">交易账户存取</span></td>
                    </tr>
                  </table>
                    <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td height="234" align="center" valign="top" bgcolor="#3676B4"><table width="50%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td height="8"></td>
                          </tr>
                        </table>
                          <table width="96%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td height="78" align="center" bgcolor="#4484c1"><table width="93%" border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td height="67"><table width="90%" height="50" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                      <td align="left">存入/取出K币：</td>
                                    </tr>
                                    <tr>
                                      <td align="left">输入数额：
                                        <input id="kbi-input" name="kbi-left" type="text" size="16" maxlength="16" />
                                        K币</td>
                                    </tr>
                                  </table></td>
                                  <td><table width="90%" height="61" border="0" cellpadding="0" cellspacing="0">
                                    <tr>
                                      <td><a id="kbi-cunru" href="#"><img src="images/cunru.gif" width="62" height="25" border="0" /></a></td>
                                    </tr>
                                    <tr>
                                      <td><a id="kbi-quchu" href="#"><img src="images/quchu.gif" width="62" height="25" border="0" /></a></td>
                                    </tr>
                                  </table></td>
                                </tr>
                              </table></td>
                            </tr>
                          </table>
                          <table width="50%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td height="8"></td>
                            </tr>
                          </table>
                          <table width="96%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              <td height="78" align="center" bgcolor="#4484c1"><table width="93%" border="0" cellspacing="0" cellpadding="0">
                                  <tr>
                                    <td height="67"><table width="90%" height="50" border="0" cellpadding="0" cellspacing="0">
                                        <tr>
                                          <td align="left">存入/取出K宝：</td>
                                        </tr>
                                        <tr>
                                          <td align="left">输入数额：
                                            <input id="kbao-input" name="kbao-left" type="text" size="16" maxlength="16" />
                                            个</td>
                                        </tr>
                                    </table></td>
                                    <td><table width="90%" height="61" border="0" cellpadding="0" cellspacing="0">
                                        <tr>
                                          <td><a id="kbao-cunru" href="#"><img src="images/cunru.gif" width="62" height="25" border="0" /></a></td>
                                        </tr>
                                        <tr>
                                          <td><a id="kbao-quchu" href="#"><img src="images/quchu.gif" width="62" height="25" border="0" /></a></td>
                                        </tr>
                                    </table></td>
                                  </tr>
                              </table></td>
                            </tr>
                          </table>
                          <table width="90%" height="57" border="0" cellpadding="0" cellspacing="0">
                            <tr>
                              <td align="left">说明：点击存入或取出，可在交易账户和总资金账户之间进行资金转移。</td>
                            </tr>
                          </table></td>
                      </tr>
                    </table></td>
                </tr>
              </table>
                <table width="50%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="7"></td>
                  </tr>
                </table>
<?php require_once "left.php"; ?>
                </td>
            </tr>
          </table>
</td>
<td width="226">
<?php require_once "top.php"; ?>
</td>
      </tr>
</table>
</td>
</tr>
</table>

<script type="text/javascript">
$(document).ready(function(){
	getUserLeft(); //计算用户剩余K

	// K宝存存入,绑定动作
	$("#kbao-cunru").click(function(){
		var num = $("#kbao-input").val();
		if( kDebug( num, $("#kbao-left").text() ) ) {
				kCunQu( 'kbao-cunru', num );
		}			
	}); //END K宝存入

	// K宝存取出,绑定动作
	$("#kbao-quchu").click(function(){
		var num = $("#kbao-input").val();
		if( kDebug( num, $("#ikbao-left").text() ) ) {
				kCunQu( 'kbao-quchu', num );
		}			
	}); //END K宝取出

	// K币存存入,绑定动作
	$("#kbi-cunru").click(function(){
		var num = $("#kbi-input").val();
		if( kDebug( num, $("#kbi-left").text() ) ) {
				//alert("K币存存入 "+num);
				kCunQu( 'kbi-cunru', num );
		}			
	}); //END K币存入

	// K币存取出,绑定动作
	$("#kbi-quchu").click(function(){
		var num = $("#kbi-input").val();
		if( kDebug( num, $("#ikbi-left").text() ) ) {
				kCunQu( 'kbi-quchu', num );
		}			
	}); //END K币取出

	
	//对存取返回的数据进行处理
	function kCunQu( act, num ){
		$.post("bg-aa.php", {
			action: act,
			user_id: '<?php echo $user_id; ?>',
			knum: num
			}, function(data, textStatus){
				if(data == '1'){
					getUserLeft();
					$("#kbao-input").val('');
					$("#kbi-input").val('');
					alert("操作成功！");
				}else if(data == '403'){
					alert("主账户登出K秀系统！");
					window.location='?uin=<?php echo $user_id; ?>&module=login';
				}else
					alert("系统错误(error:"+ data +")");
			}, 'json');
	}//END func kCunQu


	//刷新账户余额
	function getUserLeft(){
		$.post("bg-info.php", {
			action: 'getInfo',
			user_id: '<?php echo $user_id; ?>'
			}, function(data, textStatus){
				addInfoMsg( data );
			}, 'json');
	}//END func getUserLeft
	
	function addInfoMsg( data ){
		$("#ikbao-left").empty(); //交易账户
		$("#ikbi-left").empty();
		$("#ikbao-frozen").empty(); //冻结账户
		$("#ikbi-frozen").empty();
		$("#kbi-left").empty(); //本人账户
		$("#kbao-left").empty();
		
		$.each(data['info'], function(i,n){
			$("#ikbao-left").prepend(n['kbao2']); //交易账户
			$("#ikbi-left").prepend(n['kbi2']);
			$("#ikbao-frozen").prepend(n['kbao3']); //冻结账户
			$("#ikbi-frozen").prepend(n['kbi3']);		
			$("#kbi-left").prepend(n['kbi1']);   //prepend(n['kbi1']); //本人账户
			$("#kbao-left").prepend(n['kbao1']);
			});	
	} //END func addInfoMsg
	
}); //END $()

function kDebug( num, left ){
	if( isNull(num) ){
		alert("请输入数字！");
	}else if( !isInteger(num) ){
		alert("输入值必须为数字！");
	}else if( Number(num) > Number(left) ){
		alert("输入值("+ num +")大于账户余额("+ left +")！");
	}else return true;
	return false;
}//END func KDebug

function isNull(vehicleid) {
	if(vehicleid == null || vehicleid == undefined || (!vehicleid))
		return true;
	else return false;
}

function isInteger(str) { 
	   if(/^(\-?)(\d+)$/.test(str)) return true; 
	   else return false; 
}
</script>
</body></html>